package com.bckj.fastboot.iot.biz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bckj.fastboot.iot.common.dto.query.IotDeviceDataQuery;
import com.bckj.fastboot.iot.common.dto.query.IotDeviceQuery;
import com.bckj.fastboot.iot.common.dto.response.IotDeviceDataResponse;
import com.bckj.fastboot.iot.common.dto.response.IotDeviceResponse;
import com.bckj.fastboot.iot.common.entity.IotDevice;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

/**
 * IotDeviceMapper
 *
 * @author wfc
 * @date 2025/10/9 15:54
 **/
@Mapper
public interface IotDeviceMapper extends BaseMapper<IotDevice> {

    @SelectProvider(type = IotDeviceProvider.class, method = "findList")
    List<IotDeviceResponse> findList(IotDeviceQuery query);

    @Select("""
    select *
    from iot_device
    where id=#{0}
    """)
    IotDeviceResponse findById(Long id);

    @SelectProvider(type = IotDeviceProvider.class, method = "findDataList")
    List<IotDeviceDataResponse> findDataList(IotDeviceDataQuery query);

    class IotDeviceProvider {
        
        public String findList(IotDeviceQuery query) {
            SQL sql = new SQL();
            sql.SELECT("dev.*");
            sql.FROM("iot_device dev");
            listWhere(sql, query);
            return sql.toString();
        }
        
        private void listWhere(SQL sql, IotDeviceQuery query) {
            
            
        }

        public String findDataList(IotDeviceDataQuery query) {
            SQL sql = new SQL();
            sql.SELECT("dev.*");
            sql.FROM("iot_device_data dev");
            listWhere(sql, query);
            return sql.toString();
        }

        private void listWhere(SQL sql, IotDeviceDataQuery query) {

        }
    }
}
